<?php
session_start(); 
if(!isset($_SESSION['userName'])){
header( 'location: ../index.php' ); 
}

include("../conf/connect.php");
	$user_id = $_SESSION['user_id'];
	$qus_no = $_GET['qus'];
	$hid = $_SESSION['usrHHid'];
	$resId =$_SESSION['lid'];
	

  if($qus_no =='ret'){
	$hhhid = $_POST["HHHid"];	
	$_SESSION['usrHHid']=$hhhid;
	header( "location: retreive_name.php" );
  }
  elseif($qus_no =='search'){
	$search_id=$_POST['search_id'];	
	$resp_id=$_POST['memid'];
	header( "location: retrieve_detail.php?resp_id=$resp_id&search_id=$search_id" );
  }
  else if($qus_no =='upd'){
   $hhhid = $_POST["HHHid"];
   $_SESSION['usrHHid']=$hhhid;
   header( "location: update/update_name.php" );
   
  }
  else if($qus_no =='updlink'){
   $resp_id=$_POST['memid'];
   $block = $_POST['block'];
   		if($block=='1'){
   			header( "location: update/update_emp.php?resp_id=$resp_id&bid=$block" );
   		}
		elseif($block=='2'){
   			header( "location: update/update_spn.php?resp_id=$resp_id&bid=$block" );
   		}
		elseif($block=='3'){
   			header( "location: update/update_economic.php?resp_id=$resp_id&bid=$block" );
   		}
   		else{
   			header( "location: update/update_detail.php?resp_id=$resp_id&bid=$block" );
		}	
	//header( "location: update_detail.php?hhid=$hhhid&bid=$block" );
  }
  else if($qus_no =='rel_detail'){
	$back=$_POST['stn'];
	$value = explode(":",$back);
	$_SESSION['relOf']=$value[0];
	$_SESSION['name']=$value[1];
	$sql="UPDATE track set qid='rel_detail' WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
	mysql_query($sql) or die ("problem budget_heads");
	header( "location: rel_detail2.php?id=$value[0]&name=$value[1]" );
  }
  else if($qus_no =='rel_detail2'){
	$fid = $_POST['fid'];
	$mid = $_POST['mid'];
	$sid = $_POST['sid'];
	$stid = $_POST['ss1'].$_POST['ss2'];
	$oid = $_POST['oid'];
	$appid = $_SESSION['relOf'];
	$nameid= $_SESSION['name'];
	$go = $_POST['back'];
	$sql="UPDATE raw_data set q9='$fid',status='1' WHERE id='$appid' and user_id='$user_id' and hid = '$hid'";	
	mysql_query($sql) or die ("problem father");
	
	$sql="UPDATE raw_data set q10='$mid',status='1' WHERE id='$appid' and user_id='$user_id' and hid = '$hid'";	
	mysql_query($sql) or die ("problem mother");
	
	$sql="UPDATE raw_data set q11='$sid',status='1' WHERE id='$appid' and user_id='$user_id' and hid = '$hid'";	
	mysql_query($sql) or die ("problem spouse");
		
	if($go=='Continue'){
		if($sid=='Deceased'||$sid=='Lives elsewhere'){
			header( "location: rel_detail3.php?id=$appid&name=$nameid" );
		}
		else{
			header( "location: rel_detail.php" );
		}
	}
	else{
		if($sid=='Deceased'||$sid=='Lives elsewhere'){
			header( "location: rel_detail3.php?id=$appid&name=$nameid" );
		}
		else{
				if(isset($_SESSION['lid'])){
				$sql="delete from track WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
				mysql_query($sql) or die ("problem budget_heads");
				unset($_SESSION['lid']);
			}
			header( "location: hc_info.php?serial=1" );
		}
	}
  }
  else if($qus_no =='rel_detail3'){
  	$SchType = $_POST['st'];
	$stid = $_POST['ss1'].$_POST['ss2'];
	$oid = $_POST['oid'];
	$appid = $_SESSION['relOf'];
	$go = $_POST['back'];
	
	$sql="UPDATE raw_data set q12='$SchType',status='1' WHERE id='$appid' and user_id='$user_id' and hid = '$hid'";	
	mysql_query($sql) or die ("problem spouse education");	
	
	$sql="UPDATE raw_data set q13='$stid',status='1' WHERE id='$appid' and user_id='$user_id' and hid = '$hid'";	
	mysql_query($sql) or die ("problem spouse education");
	
	$sql="UPDATE raw_data set q14='$oid',status='1' WHERE id='$appid' and user_id='$user_id' and hid = '$hid'";	
	mysql_query($sql) or die ("problem spouse occupation");	
	if($go=='Repeat'){		
			header( "location: rel_detail.php" );
	}
	else{
		if(isset($_SESSION['lid'])){
			$sql="delete from track WHERE appid='$resId' and user_id='$user_id' and hid = '$hid'";
			mysql_query($sql) or die ("problem budget_heads");
			unset($_SESSION['lid']);
		}
		header( "location: hc_info.php?serial=1" );
	}
  }
  
  
?>